사이트 내 전체검색
PHP
[PHP] download.php 샘플
로빈아빠
https://cmd.kr/php/668 URL이 복사되었습니다.

본문

[ view.php ]

<a href="download.php?idx="<?=$idx?>&downFile=<?=$fileCount[$i]?>" target="bbsHidden"><?=$fileCount[$i]?></a>
<iframe name="bbsHidden" src="about:blank" style="display:none"></iframe>


[ download.php ]

<?PHP
$tableName = "테이블이름";
$idx = $_POST[idx];
$downFile = $_POST[downFile];
$strSQL = "select * from ".$tableName." where idx='".$idx."' and file LIKE '%".$downFile."%'";
$result = mysql_query($strSQL);
$reusltNum = mysql_num_rows($result);
if($reusltNum==0) {
  errNgoto("잘못된 파일정보입니다",$_SERVER['HTTP_REFERER'],"_top");
} else {
  $resultRow = mysql_fetch_array($result);
  $fileInfo = explode("|",$resultRow[file]);
  $downCount = explode("|",$resultRow[download]);
  $downCountIdx = array_search($downFile,$fileInfo);
  $downCount[$downCountIdx] = $downCount[$downCountIdx]+1;
  $strSQL = "update ".$tableName." SET download='".implode("|",$downCount)."' where idx='".$idx;
  $result = mysql_query($strSQL);
  $filePath = $_SERVER['DOCUMENT_ROOT']."/upload/".$_GET[idx]."/".$_GET[downFile];
  header("Content-Type: application/octet-stream");
  header("Content-Disposition: attachment;; filename=".$_GET[downFile]);
  header("Content-Transfer-Encoding: binary");
  header("Content-Length: ".(string)(filesize($filePath)));
  header("Cache-Control: cache, must-revalidate");
  header("Pragma: no-cache");
  header("Expires: 0");
  $fp = fopen($filePath,'r+b') ;
  if(!fpassthru($fp)){
    fclose($fp);
  }
}
?>

댓글목록

등록된 댓글이 없습니다.

PHP
871 (6/18P)

Search

Copyright © Cmd 명령어 3.22.77.149